package com.bulletelc.apollopre.module.main.center;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bulletelc.apollopre.R;
import com.bulletelc.apollopre.entity.ServiceModuleBean;

import java.util.List;

/**
 * Created by CX on 2018/3/21.
 */

public class ServiceModuleAdapter extends BaseAdapter {
    private List<ServiceModuleBean> modules;
    private LayoutInflater inflater;
    private Context context;

    public ServiceModuleAdapter(Context context, List<ServiceModuleBean> modules) {
        this.modules = modules;
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return modules.size();
    }

    @Override
    public Object getItem(int i) {
        return modules.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        final int pos = i;
        ViewHolder holderView;
        if (view == null) {
            view = inflater.inflate(R.layout.center_services_item, viewGroup, false);
            holderView = new ViewHolder(view);
            view.setTag(holderView);
        } else {
            holderView = (ViewHolder) view.getTag();
        }
        holderView.ivIcon.setImageResource(modules.get(i).getIcon());
        holderView.tvTitle.setText(modules.get(i).getText());
        return view;
    }

    class ViewHolder {
        ImageView ivIcon;
        TextView tvTitle;

        ViewHolder(View view) {
            ivIcon = view.findViewById(R.id.ivIcon);
            tvTitle = view.findViewById(R.id.tvTitle);
        }
    }
}
